<!--
 *@Author: Chen Zhi Hong
 *@Demand: 
 *@Date: 2023-05-14 21:35:27
 *@Description: 
-->
<template>
  <div class="">
    <input type="file" id="upload" />
  </div>
</template>

<script>
export default {
  name: '',
  components: {},
  props: {},
  data() {
    return {};
  },
  computed: {},
  watch: {},
  created() {},
  async mounted() {
    // 获取 input 标签的 dom
    var input = document.getElementById('upload');

    // 监听它的变化
    input.addEventListener('change', (e) => {
      // 获取到上传的 file 对象
      var file = input.files[0];
      // 声明 FormData 实例 formData
      let formData = new FormData();
      // 添加实例属性 file
      formData.append('file', file);
      formData.append('name', '图片');

      this.$Axios({
        url: 'http://127.0.0.1:7001/api/upload',
        method: 'POST',
        data: formData,
      }).then((res) => {
        const resData = res.data;

        const newStr = resData.data.replace(/\\/g, '/');
      });
    });
  },
  methods: {},
};
</script>

<style scoped lang="less"></style>
